{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "24bf4fae-a84a-4d8e-a793-69bc05214feb",
   "metadata": {},
   "source": [
    "Chapter 05\n",
    "# 常用.format() 示例\n",
    "Book_1《编程不难》 | 鸢尾花书：从加减乘除到机器学习  \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "545769e5-efb3-40b7-96f3-0d8df6d3027e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'3.14'"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"{:.2f}\".format(3.1415926)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "c7693138-bbc6-4e5a-8f38-c2a0e1e7e6ad",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'314.159260%'"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"{:%}\".format(3.1415926) #'314.159260%'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "849bd443-3036-4cf7-adc6-1c101aed301a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'314.16%'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"{:.2%}\".format(3.1415926) #'314.159260%'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "5656fe09-71a1-4902-bc13-afb9d3e211a0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'3.14e+00'"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"{:.2e}\".format(3.1415926) #'3.14e+00'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "962661c5-90b2-48e9-ab38-7beead7c8b25",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'3,141.5926'"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"{:,}\".format(3.1415926*1000) #'3,141.5926'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b1c8a248-0ca2-4663-b406-08fefbc0bc95",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "56dea739-3a32-4df5-bded-b9b9b78397da",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
